/*
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        vector<int> ret;
        int hash1[26] = { 0 }, hash2[26] = { 0 };
        for (auto ch : p)
            hash1[ch - 'a']++;
        int m = p.size();
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            char in = s[right];
            if (++hash2[in - 'a'] <= hash1[in - 'a'])
                count++;
            if (right - left + 1 > p.size())
            {
                char out = s[left++];
                if (hash2[out - 'a']-- <= hash1[out - 'a'])
                    count--;
            }
            if (count == m)
                ret.push_back(left);
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        vector<int> ret;
        unordered_map<string, int> hash1;
        for (auto word : words)
            hash1[word]++;
        int len = words[0].size(), m = words.size();
        for (int i = 0; i < len; i++)
        {
            unordered_map<string, int> hash2;
            for (int left = i, right = i, count = 0; right + len <= s.size(); right += len)
            {
                string in = s.substr(right, len);
                hash2[in]++;
                if (hash1[in] && hash2[in] <= hash1[in])
                    count++;
                if (right - left + 1 > len * m)
                {
                    string out = s.substr(left, len);
                    if (hash2[out]-- <= hash1[out])
                        count--;
                    left += len;
                }
                if (count == m)
                    ret.push_back(left);
            }

        }
        return ret;

    }
};

class Solution {
public:
    string minWindow(string s, string t) {
        int hash1[128] =  { 0 }, hash2[128] = { 0 }, kinds = 0;
        for (auto ch : t)
            if (hash1[ch]++ == 0)
                kinds++;
        int minlen = INT_MAX, begin = -1;
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            char in = s[right];
            if (++hash2[in] == hash1[in])
                count++;
            while (count == kinds)
            {
                if (right - left + 1 < minlen)
                {
                    minlen = right - left + 1;
                    begin = left;
                }
                char out = s[left++];
                if (hash2[out]-- == hash1[out])
                    count--;
            }
        }
        if (begin == -1)
            return "";
        else
            return s.substr(begin, minlen);
    }
};

*/